import QtQuick
import EcgModel 1.0
import "utils.js" as Utils

Item {
    id:fragmentBeatsInfo
    anchors.fill: parent
    property int start
    property int duration: 16000 //持续时长毫秒
    property list<int> padding : [0,0,0,0]
    Repeater {
        model: fragmentBeatsList
        Item{
            width: 50
            x: fragmentBeatsInfo.width / (duration/1000*EcgModel.sampleRate) * (rPeaksInAll - (start >=0?start:0)) - width/2
            y: 5
            Text {
                text: label+ "," + qOffset + "," + sOffset
                font.pixelSize: 12
                horizontalAlignment: Text.AlignHCenter
                color: selected?"#ee6600":"#666666"
                width: parent.width
                font.bold: selected?true:false
                y:0
            }
            Text {
                text: (rrIntervals ? Math.round(60 * 1000 / rrIntervals): "-")
                font.pixelSize: 12
                horizontalAlignment: Text.AlignHCenter
                color: selected?"#ee6600":"#666666"
                width: parent.width
                font.bold: selected?true:false
                y:16
            }
            Text {
                text: rrIntervals || "-"
                font.pixelSize: 12
                horizontalAlignment: Text.AlignHCenter
                color: selected?"#ee6600":"#666666"
                width: parent.width
                font.bold: selected?true:false
                y:32
            }
            Text {
                text: test1/10+ "-" + test3
                font.pixelSize: 12
                horizontalAlignment: Text.AlignHCenter
                color: selected?"#ee6600":"#666666"
                width: parent.width
                font.bold: selected?true:false
                y:48
            }
            Text {
                text: test2/1000 || "-"
                font.pixelSize: 12
                horizontalAlignment: Text.AlignHCenter
                color: selected?"#ee6600":"#666666"
                width: parent.width
                font.bold: selected?true:false
                y:64
            }
        }
    }
    //刻度
    Repeater {
        model:  fragmentBeatsInfo.duration/1000 + 1. // 重复次数
        Rectangle {
            width: 1 // 竖线的宽度
            height: 6 // 竖线的高度
            color: "#666666" // 竖线的颜色
            y: parent.height - height // 竖线位于容器的底部
            x: index * (parent.width / (fragmentBeatsInfo.duration/1000)) -0.5 // 计算竖线的水平位置
        }
    }
    Repeater {
        model:  parseInt(fragmentBeatsInfo.duration/1000/2) // 重复次数
        Item{
            width: 200
            x: (index*2 + 1) * parent.width / (fragmentBeatsInfo.duration/1000)  - width/2
            y:  parent.height - 20
            Text {
                text: Utils.formatTime(EcgModel.startTimeStamp + index*2 + 1 + (fragmentBeatsInfo.start >=0?fragmentBeatsInfo.start:0) / EcgModel.sampleRate )
                font.pixelSize: 12
                horizontalAlignment: Text.AlignHCenter
                color: "#666666"
                width: parent.width
                y:0
            }
        }
    }
    onStartChanged:{
        // console.log(fragmentBeatsInfo.start)
        fragmentBeatsList.getFragmentBeats(start,duration);
    }
}
